import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

class SerialTapGestureDetector extends StatelessWidget {
  final int serialTapCount;
  final VoidCallback onSerialTap;
  final Widget? child;

  const SerialTapGestureDetector({
    Key? key,
    required this.serialTapCount,
    required this.onSerialTap,
    this.child,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return RawGestureDetector(
      gestures: {
        SerialTapGestureRecognizer:
            GestureRecognizerFactoryWithHandlers<SerialTapGestureRecognizer>(
          () => SerialTapGestureRecognizer(),
          (SerialTapGestureRecognizer instance) {
            instance.onSerialTapDown = (SerialTapDownDetails details) {
              if (details.count == serialTapCount) {
                onSerialTap();
              }
            };
          },
        )
      },
      child: child,
    );
  }
}
